<?php
//error_reporting(0);
define('DEBUG_GRADE_',3);

function _debug($str,$nGrade=3){
	//$nGrade数字越小越容易显示
  
    return $nGrade<DEBUG_GRADE_ ? $str : ""; 
}
//echo  _debug("fdsgfffffffffffffff",1);
function secho($array, $eixt=0) {
	if(is_array($array)) {
		 echo '<pre>';
		 print_r($array);
		 echo '</pre>';
	} else {
		echo '<br>';
		echo shtmlspecialchars($array);
		echo '<br>';
	}
	if($eixt) exit();
}
function shtmlspecialchars($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = shtmlspecialchars($val);
		}
	} else {
	$string =str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
	}
	return "".$string."";
}
$_DG['mf']['get_defined_functions']=
'get_defined_functions'
.'||__sys:||取得系统定义的函数名';
$_DG['mf']['_gufunc']=
'_gufunc'
.'||__user:||取得所有用户定义的函数';
$_DG['mf']['var_dump']=
'var_dump';	  
	  
function _info(){
	global $_DG;
	secho(_gufunc());
	echo(   _spre(print_my2($_DG['mf'])) );
}
/*************************************************/
function _get_user_func(){
    $array=get_defined_functions();
    return $array['user'];
}
function _get_func(){
    $array=get_defined_functions();
    return $array['internal'];
}
define('GF','get_defined_functions()');
$_FX['secho']='secho';
function _str2arr($str,$arg2=" "){
  //  return explode($arg2,$str);
  //return split($arg2,$str);
  return preg_split($arg2,$str);
}
function _arr2str($arr,$arg2="--"){
    return implode($arg2,$arr);
}
/**************************************************/

/**********************start*****code assistant  代码助手**************/
function _codeassi_get_inc(){
    return _arr2str(glob("*.*"),"\n");	
}
//echo _codeassi_get_inc();
//secho(_get_user_func());

/**********************end***************************/
function _getselfurl(){
	//得到当前页面的url地址
	if(80==$_SERVER[SERVER_PORT]||8080==$_SERVER[SERVER_PORT]){
		$server_port_str='';
		}else{
		$server_port_str=':'.$_SERVER[SERVER_PORT];
		}
		return 'http://'.$_SERVER[SERVER_NAME].$server_port_str.$_SERVER[REQUEST_URI];
}
//echo _getselfurl();

//得到“ascci码字和对应字符”组成的“数组序列”
function _get_ascii_tab($start=33,$end=256){
    $ret=array();
    for($i=$start;$i<$end;$i++){
    $ret[]=array( "ASCII"=> $i   ,"value"=> chr($i)  )  ;
    }
	return $ret;
}


function _print_r($v,$left=-1,$ret="MY_tree\n"){
$left+=1;
if (is_array($v) ){
    $ret=$ret."Array\n".str_repeat('  ',$left*4)."(\n";
    foreach ($v as $key=>$val)
    {
        $ret=$ret.str_repeat('  ',$left*4+2)."[$key] => ";
        if (is_array($val)){$ret=_print_r($val,$left,$ret);}
        else {$ret=$ret."$val\n";}
        
    }
    $ret=$ret.str_repeat('  ',$left*4).")\n";
}
else 
{  $ret=$ret.$v; }
   return $ret;
}

// _print_tree(array,string 当前树id不以数字开头,string,int)
//_print_tree 参数1为必需有，传入一个多维数组，得到一个多维数组的目录树
function _print_tree($v,$jsfuncname='_h',$ret="MY_menu_tree\n"){
	//本函数必须包含jquery.js
    $treecon=_print_tree_fx($v,$jsfuncname,$ret);
	$jscon='
<script>
function '.$jsfuncname.'(chClass){
	$(chClass).each(
		    function(){
				    if(this.style.display!="none"){
				    this.style.display="none";						
				    }else{
					 this.style.display="block";						
					}
			}	
    )
}
</script>';
	return $jscon." ".$treecon." ";
}

function _print_tree_fx($v,$jsfuncname='_h',$ret="MY_tree\n",$left=-1,$keyid='r'){
$left+=1;
$keyid_father=$keyid;
if (is_array($v)  ){
	$class='".'.$jsfuncname.'____'.($keyid).'"';
    $ret=$ret.str_repeat('  ',$left*4*1)."<div class='xxx' style='margin:0px; border:0px solid #eee;".
	" width:200px; margin:5px; padding:5px;'><a style='border:1px solid #666 ;' href='javascript:".
	$jsfuncname."(".$class.");' >[".$left."|".$keyid.
	"]Array</a></div>	
	".str_repeat('  ',$left*4)."<ol style='display:block;' class='".$jsfuncname."____".$keyid."' >\n".str_repeat('  ',$left*4)."<b>(</b>\n";
    foreach ($v as $key=>$val)
	{   
       //$ret=$ret.str_repeat('  ',$left*4*0+2*0)."<span style='color:red;'>[$key] =></span> ";
	   $keyid=$key;
	   $keyid=$keyid_father."--".$keyid."";
        if (is_array($val)){$ret=_print_tree_fx($val,$jsfuncname,$ret,$left,$keyid);}
        else {$ret=$ret.str_repeat('  ',$left*4+2).'<li style="margin-left:'.($left*1).'px;">['.$key.']=>'.$val."</li>\n";}
		
    }
    $ret=$ret.str_repeat('  ',$left*4)."<b>)</b>\n".str_repeat('  ',$left*4+4)."</ol>\n";
}
else 
{  $ret=$ret.'<li>'.$v."</li>"; }
   return $ret;
}


function _get_query_string($url,$name){
	 $ms;	 
	 $result=preg_match("/(?:\?|&)" . $name . "\=([^&]*)(?:&|$)/is",$url,$ms); 
	 return $result?$ms[1]:NULL;	
}

function _write_self_to_html(){
	if(empty($url)){
	    preg_match("/\/{1}([a-zA-Z0-9\._]{1,})$/i",$_SERVER['PHP_SELF'],$ms);
		$url = $ms[1];
	}
	echo '<iframe src="'.$url.'?action=w" style="display:none;"></iframe>';	
	if($_REQUEST['action']=='w'){
		echo _fwf($url.".html",file_get_contents("http://".$_SERVER[SERVER_NAME].":".$_SERVER[SERVER_PORT]."/".$_SERVER['PHP_SELF']))?"ok":"error";	
	}
}


function _define_inclde_path($constName,$addStr='',$currentDir='/inc[\/\\\\]?/'){
	define
	($constName,     	 
		preg_replace 
		( 
		array('/\/{1,}/', $currentDir), 
		array('/'       ,''          ),
				   str_replace( 
				   '\\',
				   '/' , 
					str_replace('//','/',dirname(__FILE__).DIRECTORY_SEPARATOR)
				   )   
		).(empty($addStr)?'':$addStr.'/')	 	 
	);	
}

?> 